﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    class DBHelper
    {

        static string str = "server=.;database=Stock;Integrated Security=true";
        static SqlConnection coon = new SqlConnection(str);
        public static DataTable Select(string sql)
        {
            //适配器
            SqlDataAdapter sda = new SqlDataAdapter(sql, coon);
            //数据击
            DataSet ds = new DataSet();
            sda.Fill(ds);
            return ds.Tables[0];
        }

        //增删改
        public static int NoSelect(string sql)
        {
            //打开连接
            coon.Open();
            //执行命令对象
            SqlCommand comm = new SqlCommand(sql, coon);
            int num = comm.ExecuteNonQuery();
            //关闭连接
            coon.Close();
            return num;
        }
    }
}
